<-?php


namespace app\{$data.module_name}\controller;

use app\common\model\{$data.model_name};
use think\response\Json;
use think\facade\Request;

/**
* {$data.table_desc} 控制器
* Class {$data.controller_name}

* @package app\{$data.module_name}\controller
*/
class {$data.controller_name} extends Controller
{

    /**
    * 更新或者保存数据
    * @return Json
    */
    public function saveData(): Json
    {
        try {
            $param = Request::param('post.');
            if(isset($param['{$data.pk}'])){
                {$data.model_name}::updateModel($param);
            }else{
                {$data.model_name}::createModel($param);
            }
        }catch (\Exception $e){
            return json(['code'=>50000,'message'=>$e->getMessage()]);
        }
    }

    /**
    * 查询详情信息
    */
    public function getDetail(): Json
    {
        try{
            $data =  Request::param('{$data.pk}');
            $result  =  {$data.model_name}::getDetail($data);
            return json(['code' => 20000, 'data' => $result,'message'=>'查询成功']);
        }catch (\Exception $e){
            return json(['code'=>50000,'message'=>$e->getMessage()]);
        }
    }

    /**
    * 分页查询列表
    * @return Json
    */
    public function getList(): Json
    {
        try {
            $param = Request::param('post.');
            $data = {$data.model_name}::getList($param);
            $data['code'] = 20000;
            $data['message'] = '成功';
            return json($data);
        }catch (\Exception $e){
            return json(['code'=>50000,'message'=>$e->getMessage()]);
        }
    }
    /**
    * 分页查询列表
    * @return Json
    */
    public function deleteData(): Json
    {
        try {
            $ids = Request::param('post.ids');
{if $data.soft_delete}
            //软删除
            {$data.model_name}::deleteBatch($ids,true);
{else/}
            //物理删除
            {$data.model_name}::deleteBatch($ids);
{/if}
            return json(['code' => 20000, "message" => "删除成功"]);
        }catch (\Exception $e){
            return json(['code'=>50000,'message'=>$e->getMessage()]);
        }
    }
}